/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path);
}

/**
 * @description 验证手机号
 * @param {*} poneInput
 * @returns
 */
export function isPoneAvailable(poneInput) {
  var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
  if (!myreg.test(poneInput)) {
    return false;
  } else {
    return true;
  }
}
/**
 * @description 验证邮箱
 * @param {*} emailInput
 * @returns
 */
export function isEmailAvailable(emailInput) {
  var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  if (!myreg.test(emailInput)) {
    return false;
  } else {
    return true;
  }
}
/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  // const valid_map = ['admin', 'editor']
  // return valid_map.indexOf(str.trim()) >= 0
  return true;
}
//时间戳转  yy-mm-dd hh：mm：ss  day:往前推多少天
export function timestampToTime(timestamp,day) {
  var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
  day&&date.setTime(date.getTime() - 3600 * 1000 * 24 * day)
  var Y = date.getFullYear() + '-';
  var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1):date.getMonth()+1) + '-';
  var D = (date.getDate()< 10 ? '0'+date.getDate():date.getDate())+ ' ';
  var h = (date.getHours() < 10 ? '0'+date.getHours():date.getHours())+ ':';
  var m = (date.getMinutes() < 10 ? '0'+date.getMinutes():date.getMinutes()) + ':';
  var s = date.getSeconds() < 10 ? '0'+date.getSeconds():date.getSeconds();
  return Y+M+D+h+m+s;
}

export function dateToFormat(originDate) {
  const dt = new Date(originDate);
  const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + "").padStart(2, "0");
  const d = (dt.getDate() + "").padStart(2, "0");

  const hh = (dt.getHours() + "").padStart(2, "0");
  const mm = (dt.getMinutes() + "").padStart(2, "0");
  const ss = (dt.getSeconds() + "").padStart(2, "0");

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
}
export function dateToFormattwo(originDate) {
  const dt = new Date(originDate);
  const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + "").padStart(2, "0");
  const d = (dt.getDate() + "").padStart(2, "0");
  return `${y}-${m}-${d}`;
}
export function dateToFormatname(originDate) {
  const dt = new Date(originDate);
  const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + "").padStart(2, "0");
  const d = (dt.getDate() + "").padStart(2, "0");
  return `${y}年-${m}月-${d}日`;
}
export function dateToFormatthree(originDate) {
  const dt = new Date(originDate);
  const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + "").padStart(2, "0");
  // const d = (dt.getDate() + "").padStart(2, "0");
  return `${y}-${m}`;
}
// 判断水产养殖 不能出现病虫害
export function farmingTypeTitle() {
  let farmingTypeNo = sessionStorage.farmingTypeNo;
  console.log(farmingTypeNo)
  if (farmingTypeNo === "sc") {
    return "病害";
  } else if (farmingTypeNo === "gc") {
    return "病害";
  } else {
    return "病虫害";
  }
}
// 点击跳转对应地方
export function toLocal(loc) {
  let toElement = document.getElementById(loc)
  toElement.scrollIntoView({
    behavior: "smooth", // 平滑过渡
    block: "start" // [可选] "start"，"center"，"end"或"nearest"。默认为"center"
  })
}

